/**
 * 
 */
package ptvv.sample.second;

import ptvv.*;

/**
 * @author dkz
 * 
 */
public class Delay extends DefaultAutomata {
	// Private Variables
	String message;

	public Delay(DefaultAutomata destination, Thread dest) {
		this();
		outputPort = new OutputPort(destination, dest);

	}

	public Delay() {
		this.setName("Delay");

	}

	public void run() {
		while (internalState != InternalStates.ReallyDead)
			runStates();

		// logger.log("SHUTDOWN");
	}

	public void starting() throws InterruptedException {

		String item = eventQueue.take();
		// System.out.println(item);

	}

	public void ready() throws InterruptedException {
		message = inputPort.take();
	}

	public void running() throws InterruptedException {
		// Thread.sleep(Long.parseLong(message));
		Thread.sleep(Long.parseLong(message) * 1000);
		// System.out.println("sleeping..");
		// System.out.println("awake");
	}

	public void suspended() throws InterruptedException {

	}

	public void end() {
		// System.out.println("end");
		logger.log("" + this.getName() + " : " + message);
		outputPort.destThread.interrupt();
		repeatBool = true;
	}

	public void dead() {
		// this.internalState = InternalStates.Start;

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}
